<template>
  <div>
    <div>
      <label for="orderNo">订单号：</label>
      <input id="orderNo" v-model="orderInfo.orderNo" />
      <button @click="showFn">查询</button>
    </div>
    <div class="logistics-info" v-show="isShow">
      <CommodityInfo :goodInfo="goodInfo">
        <!-- 把type 和 desc传过来实现文字或者图片显示 -->
        <template #desc="{ desc, type }">
          <strong v-if="type === 0">{{ desc }}</strong>
          <img width="100" v-else-if="type === 1" :src="desc" />
        </template>
      </CommodityInfo> 
                                            <!-- :uname.sync 和子组件实现实时更新 -->
      <Physical :logisticsInfo="logisticsInfo" :orderInfo="orderInfo" :uname.sync="uname">
        <!-- 物流头部区域 -->
        <template #header="{ logisticsNo, logisticsCompany, logisticsStatus }">
          <div class="logistics-status blue" v-if="logisticsStatus === 0">
            未发货
          </div>
          <div class="logistics-status blue" v-if="logisticsStatus === 1">
            已发货
          </div>
          <div class="logistics-status blue" v-if="logisticsStatus === 2">
            已签收
          </div>
          <div class="logistics-status blue" v-if="logisticsStatus === 3">
            未签收
          </div>
          <div class="logistics-company">{{ logisticsCompany }}</div>
          <div class="logistics-no">{{ logisticsNo }}</div>
        </template>
        <template #list="{ logisticsInfo }">
        <!-- 物流详情区域 v-fff="uname" 自定义指令 接收物流组件的uname-->              
          <li v-for="(item, index) in logisticsInfo" :key="index" >
            <div class="logistics-info-list-time">{{ item.time }}</div>
            <div class="logistics-info-list-content">{{ item.content }}</div>
          </li>
        </template>
      </Physical>
    </div>
  </div>
</template>

<script>
import CommodityInfo from './components/day06-商品组件.vue'
import Physical from './components/day06-物流组件.vue'
export default {
  components: {
    CommodityInfo,
    Physical,
  },
  data() {
    return {
      isShow: false, //大盒子显示
      uname:'',//判断是否本人名字 可以点开物流详情
      orderInfo: {
        orderNo: '',
        logisticsNo: 'SF123456789', // 快件运单号
        role: '张三', // 角色 ==> 用于判断是否有查看用户详情的权限
        logisticsStatus: 2, // 0 未发货 1 已发货 2 已签收 3 未签收
        logisticsCompany: '顺丰速运', // 快递公司的名称
      },
      logisticsInfo: [
        {
          time: '2023-02-01 10:00:00', // 时间
          content: '快件已发货', // 快递状态
        },
        {
          time: '2023-02-02 09:00:00',
          content: '快件到达深圳中心',
        },
        {
          time: '2023-02-03 08:00:00',
          content: '快件派送中',
        },
        {
          time: '2023-02-04 16:00:00',
          content: '已签收',
        },
      ],
      goodInfo: {
        // 商品信息
        goodNo: '12345678912312', // 商品id
        goodName: '三体', // 商品名称
        type: 1, // 0 代表的是文本 1代表的是 图片
        desc: 'https://img2.baidu.com/it/u=3680809226,4204478496&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1679677200&t=df6f33d667e14d92f8a31b13f04f8210',
        // desc 描述 ==> 可以是图片 也可以是其他的东西。数据可以随便改
      },
    }
  },
  methods: {
    showFn() {
      if (this.orderInfo.orderNo !== '') {
          this.isShow = true
        }
    },
  },
  // directives:{
  //   fff:{
  //     inserted(el){//el 代表绑定的元素 li标签
  //       el.style.display = "none"
  //     },
  //     update(el,binding){ //binding 当前指令的一系列信息 .value 是指令的绑定值
  //       el.style.display = binding.value === "张三" ? "block" :"none";
  //     }
  //   }
  // }
}
</script>
<style>
.logistics-info {
  border: 1px solid #ccc;
  border-radius: 5px;
  box-shadow: 0px 0px 10px #eee;
  padding: 10px;
  font-size: 14px;
}

.logistics-info-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.logistics-info-header-left {
  display: flex;
  align-items: center;
}

.logistics-status {
  font-weight: bold;
  font-size: 16px;
  color: #007bff;
}

.logistics-company,
.logistics-no {
  margin-left: 10px;
  font-size: 14px;
  color: #333;
}

.logistics-info-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 230px;
  overflow-y: auto;
}

.logistics-info-list li {
  display: flex;
  margin-bottom: 10px;
}

.logistics-info-list-time {
  font-size: 12px;
  color: #999;
  width: 80px;
  text-align: right;
  margin-right: 10px;
}

.logistics-info-list-content {
  font-size: 14px;
  color: #333;
}
</style>
